<template>
  <div class="detailContainer">
    <div
      style="
        height: 100%;
        padding-left: 150px;
        padding-right: 150px;
        overflow-y: auto;
        padding-bottom: 70px;
      "
    >
      <div style="padding: 20px">
        <el-card>
          <div style="display: flex; justify-content: space-between">
            <div>
              <div class="title">
                <span class="name">{{ detailData.returnName }}</span>
                <span class="id">{{ detailData.returnId }}</span>
              </div>
              <div class="detailInfo">
                <div class="createInfo">
                  <span style="font-size: 15px"
                    >创建人：<span style="font-size: 14px; color: #969696">{{
                      detailData.creator
                    }}</span></span
                  >
                  <span style="font-size: 15px; margin-left: 20px"
                    >创建时间：<span style="font-size: 14px; color: #969696">{{
                      dayjs(detailData.createdAt).format("YYYY-MM-DD")
                    }}</span></span
                  >
                </div>
                <div class="updateInfo">
                  <span style="font-size: 15px"
                    >更新人：<span style="font-size: 14px; color: #969696">{{
                      detailData.updater
                    }}</span></span
                  >
                  <span style="font-size: 15px; margin-left: 20px"
                    >更新时间：<span style="font-size: 14px; color: #969696">{{
                      dayjs(detailData.updatedAt).format("YYYY-MM-DD")
                    }}</span></span
                  >
                </div>
              </div>
              <div class="buttonGroup" style="margin-top: 20px">
                <el-button
                  type="primary"
                  plain
                  style="width: 80px"
                  v-if="detailData.ifReturn == '未退货'"
                  >退货</el-button
                >
                <el-button
                  type="primary"
                  plain
                  style="width: 80px"
                  v-if="detailData.ifReturn == '未退货'"
                  >编辑</el-button
                >
                <el-button
                  type="primary"
                  plain
                  style="width: 80px"
                  v-if="detailData.ifReturn == '未退货'"
                  >删除</el-button
                >
                <el-button
                  type="primary"
                  plain
                  style="width: 80px"
                  v-if="detailData.ifReturn == '已退货'"
                  >撤回</el-button
                >
                <el-button type="primary" plain style="width: 80px"
                  >打印</el-button
                >
              </div>
            </div>
            <div>
              <img
                style="width: 80px"
                :src="`/public/returnImgs/${
                  detailData.ifReturn == '未退货'
                    ? 'noReturn.png'
                    : 'return.png'
                }`"
                alt=""
              />
            </div>
          </div>
        </el-card>
        <el-card style="margin-top: 20px">
          <template #header>
            <span style="font-size: 16px">入库详情</span>
          </template>
          <div class="basicBody">
            <div class="basicInfoContainer">
              <div class="milestone">
                <div class="milestone-content">基础信息</div>
              </div>
              <el-descriptions
                style="margin-top: 40px; width: 100%"
                column="2"
                label-width="120"
              >
                <el-descriptions-item label="退货单编号">{{
                  detailData.returnId
                }}</el-descriptions-item>
                <el-descriptions-item label="退货单名称">{{
                  detailData.returnName
                }}</el-descriptions-item>
                <el-descriptions-item label="退货日期">{{
                  detailData.returnDate
                }}</el-descriptions-item>
                <el-descriptions-item label="采购单名称">{{
                  detailData.purchaseName
                }}</el-descriptions-item>
                <el-descriptions-item label="采购单号">{{
                  detailData.purchaseId
                }}</el-descriptions-item>
                <el-descriptions-item label="供应商">{{
                  detailData.supplierName
                }}</el-descriptions-item>
                <el-descriptions-item label="备注">{{
                  detailData.remark
                }}</el-descriptions-item>
              </el-descriptions>
            </div>
            <div class="warehouseContainer">
              <div class="milestone">
                <div class="milestone-content">退货明细</div>
              </div>
              <div class="buttonGroup" style="margin-top: 20px">
                <el-button type="primary" plain style="width: 80px"
                  >导出</el-button
                >
              </div>
              <el-table border style="margin-top: 40px" :data="tableData">
                <el-table-column
                  align="center"
                  type="index"
                  label="序号"
                  width="60"
                  fixed="left"
                ></el-table-column>
                <el-table-column
                  align="center"
                  label="物料编号"
                  width="90"
                  fixed="left"
                >
                </el-table-column>
                <el-table-column
                  align="center"
                  label="物料名称"
                  width="90"
                  fixed="left"
                >
                </el-table-column>
                <el-table-column align="center" label="规格型号" width="90">
                </el-table-column>
                <el-table-column align="center" label="单位" width="90">
                </el-table-column>
                <el-table-column align="center" label="批次号" width="90">
                </el-table-column>
                <el-table-column align="center" label="退货数量" width="90">
                </el-table-column>
                <el-table-column align="center" label="仓库名称" width="90">
                </el-table-column>
                <el-table-column align="center" label="库区名称" width="90">
                </el-table-column>
                <el-table-column align="center" label="库位名称" width="90">
                </el-table-column>
                <el-table-column align="center" label="负责人" width="90">
                </el-table-column>
                <el-table-column align="center" label="备注" width="200">
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-card>
      </div>
    </div>
    <div class="footer" :class="{ 'footer-visible': isFooterVisible }">
      <div class="footerButton">
        <el-button type="primary" plain style="width: 80px" @click="close"
          >关闭</el-button
        >
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter, useRoute } from "vue-router";
import { onMounted, ref } from "vue";
import { getSupplierDetailApi } from "@/api/Supplier";
import { SupplierData } from "@/api/Supplier/res";
import { ElMessage } from "element-plus";
import dayjs from "dayjs";
const $router = useRouter();
const $route = useRoute();

//mockData
let detailData = ref<SupplierData>({
  remark: "", //备注
  purchaseId: "", //采购单号
  purchaseName: "", //采购单名称
  updatedAt: "",
  returnName: "", //退货单名称
  returnNum: "",
  objectId: "",
  createdAt: "",
  supplierName: "", //供应商
  returnDate: "", //退货日期
  returnId: "", //退货单编号
  ifReturn: "",
});
let tableData = ref([{}]);
const isFooterVisible = ref(false);

onMounted(async () => {
  setTimeout(() => {
    isFooterVisible.value = true;
  }, 100);
  try {
    const res: SupplierData = await getSupplierDetailApi(
      $route.query.objectId as string
    );
    detailData.value = res;
  } catch (err: any) {
    ElMessage({ type: "error", message: err.message });
  }
});

const close = () => {
  $router.replace("/storage/entrance/supplier");
};
</script>

<style scoped lang="scss">
.detailContainer {
  width: 100%;
  position: relative;
  height: 100%;
  transform: translate(0);
  .title {
    .name {
      font-weight: bold;
      font-size: 18px;
    }
    .id {
      color: #969696;
      font-size: 13px;
      margin-left: 10px;
    }
  }
  .detailInfo {
    margin-top: 10px;
    display: flex;
  }
  .updateInfo {
    margin-left: 40px;
  }
  .basicBody {
    width: 100%;
    .basicInfoContainer,
    .warehouseContainer {
      padding: 20px;
      .milestone {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 1.5px;
        background-color: #dfe2e7;
        .milestone-content {
          border: 1.5px solid #dfe2e7;
          padding: 10px;
          padding-left: 20px;
          padding-right: 20px;
          font-weight: bold;
          font-size: 15px;
          border-radius: 10px;
          z-index: 999;
          background-color: #fff;
          color: #1b9aee;
        }
      }
    }
    .warehouseContainer {
      margin-top: 20px;
    }
  }
  .footer {
    z-index: 999;
    width: 100%;
    height: 70px;
    background-color: #fff;
    position: fixed;
    bottom: 0;
    left: 0;
    padding: 10px;
    display: flex;
    justify-content: center;
    box-shadow: 0 -8px 10px rgba(92, 92, 92, 0.1);
    transform: translateY(100%); // 初始状态在视口下方
    transition: transform 0.5s ease-out; // 添加过渡效果

    &.footer-visible {
      transform: translateY(0); // 显示时回到原位
    }
  }
}
</style>
